package com.ruoyi.web.controller.app.borehole;

import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.helper.LoginHelper;
import com.ruoyi.web.domain.query.BhPlansPageQuery;
import com.ruoyi.web.domain.query.ExecutePlanQuery;
import com.ruoyi.web.domain.query.PunchCardQuery;
import com.ruoyi.web.domain.vo.AppPlanDetailVO;
import com.ruoyi.web.domain.vo.BhPlansPageVO;
import com.ruoyi.web.service.BhPlansService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "检查计划管理-App端")
@RestController
@RequestMapping("/app/checkPlan")
public class AppCheckPlanController {
    @Autowired
    private BhPlansService bhPlansService;

    @Operation(summary = "查询检查计划个数")
    @GetMapping("/getPlanNum")
    public R<Integer> getPlanNum() {
        return bhPlansService.getPlanNum();
    }

    @Operation(summary = "检查计划列表页 - 分页查询")
    @GetMapping("/getPlanPage")
    public TableDataInfo<BhPlansPageVO> getPlanPage(@Validated(QueryGroup.class) BhPlansPageQuery bhPlansPageQuery, PageQuery pageQuery) {
        bhPlansPageQuery.setExecutors(String.valueOf(LoginHelper.getUserId()));
        return bhPlansService.getPlanPage(bhPlansPageQuery, pageQuery, true);
    }

    @Operation(summary = "检查计划-打卡")
    @RepeatSubmit
    @PostMapping("/punchCard")
    public R<Void> punchCard(@RequestBody PunchCardQuery punchCardQuery) {
        return bhPlansService.punchCard(punchCardQuery);
    }

    @Operation(summary = "检查计划列表")
    @GetMapping("/getPlanList")
    public R<List<AppPlanDetailVO>> getPlanList(@RequestParam("id") Integer id) {
        return bhPlansService.getAppPlanList(id);
    }

    @Operation(summary = "检查计划-执行计划")
    @RepeatSubmit
    @PostMapping("/executePlan")
    public R<Void> executePlan(@RequestBody ExecutePlanQuery executePlanQuery) {
        if (executePlanQuery.getId() == null) {
            return R.fail("计划id不能为空！");
        }
        return bhPlansService.executePlan(executePlanQuery);
    }
}
